package com.woniuxy.educationplatform.mapper;

import com.woniuxy.educationplatform.bean.*;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.mapping.FetchType;

import java.util.Date;
import java.util.List;

@Mapper
public interface VideoMapper {
    /**
     * 查询所有
     * @return
     */

    @Select("select id, video_name as videoName,video_address as videoAddress,video_no as videoNo ,create_time as createTime from video")
    List<VideoBean> findAll();


    /**
     * 根据id查询视频
     * @param id
     * @return
     */
    @Results({
            @Result(id = true,property = "id",column = "id",javaType = Long.class),
            @Result(property = "videoName",column = "video_name",javaType = String.class),
            @Result(property = "videoAddress",column = "video_address",javaType = String.class),
            @Result(property = "videoNo",column = "video_no",javaType = String.class),
            @Result(property = "createTime",column = "create_time",javaType = Date.class),
            @Result(property = "knowpointBean",column = "fk_knowpoint_id",javaType = KnowpointBean.class,one =
            @One(select = "com.woniuxy.educationplatform.mapper.KnowpointMapper.findById",fetchType = FetchType.LAZY)),
            @Result(property = "teacherBean",column = "fk_teacher_id",javaType = TeacherBean.class,one =
            @One(select = "com.woniuxy.educationplatform.mapper.TeacherMapper.findById",fetchType = FetchType.LAZY)),
            @Result(property = "sectionBean",column = "fk_section_id",javaType = SectionBean.class,one =
            @One(select = "com.woniuxy.educationplatform.mapper.SectionMapper.findById",fetchType = FetchType.LAZY)),
            @Result(property = "courseBean",column = "fk_course_id",javaType = CourseBean.class,one =
            @One(select = "com.woniuxy.educationplatform.mapper.CourseMapper.findById",fetchType = FetchType.LAZY)),
            @Result(property = "subjectBean",column = "fk_subject_id",javaType = SubjectBean.class,one =
            @One(select = "com.woniuxy.educationplatform.mapper.SubjectMapper.findById",fetchType = FetchType.LAZY)),
            @Result(property = "projectBean",column = "fk_project_id",javaType = ProjectBean.class,one =
            @One(select = "com.woniuxy.educationplatform.mapper.ProjectMapper.findById",fetchType = FetchType.LAZY))


    })
    @Select("select * from video where id = #{id}")
    VideoBean findById(Long id);

    @Insert("insert into video (video_no,video_name,video_address,create_time,fk_knowpoint_id,fk_teacher_id,fk_section_id,fk_course_id,fk_subject_id,fk_project_id)" +
            "values(#{v.videoNo},#{v.videoName},'https://www.bilibili.com/video',now(),#{v.knowpointBean.id},#{v.teacherBean.id},#{v.sectionBean.id},#{v.courseBean.id},#{v.subjectBean.id},#{v.projectBean.id})")

    void saveVideoBean (@Param("v") VideoBean videoBean);

    @Delete("delete from video where id = #{id}")
    void deleteVideoBean(Long id);



    void update(@Param("v") VideoBean videoBean);



    List<VideoBean> findOneByCondition(@Param("v") VideoBean videoBean);

}
